package com.jwt.demo.controller;
import com.jwt.demo.config.RolePermission;
import com.jwt.demo.config.UserLoginPermission;
import com.jwt.demo.db.bean.UserLogin;
import com.jwt.demo.model.UserLoginModel;
import com.jwt.demo.service.UserLoginService;
import com.jwt.demo.util.JsonResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

@RestController
@RequestMapping(method = RequestMethod.POST,path = "/user")
@UserLoginPermission(role = RolePermission.COMMON)
public class UserLoginController {

    @Autowired
    private UserLoginService userLoginService;

    /**
     * 用户注册
     * @author chenlirun
     * @date 2021/7/14 10:46
     */
    @PostMapping("/insert")
    @UserLoginPermission(role = RolePermission.COMMON,login = false)
    public JsonResult insert(@RequestBody UserLoginModel userLoginModel){
        return userLoginService.insert(userLoginModel);
    }

    /**
     * 用户登录
     * @author chenlirun
     * @date 2021/7/14 16:06
     */
    @PostMapping("/login")
    @UserLoginPermission(role = RolePermission.COMMON,login = false)
    public JsonResult login(@RequestBody UserLogin userLogin, HttpServletRequest request){
        return userLoginService.login(userLogin,request);
    }

    /**
     * 查看个人信息
     * @author chenlirun
     * @date 2021/7/17 15:08
     */
    @PostMapping("/message")
    public JsonResult<List<UserLoginModel>> selectPersonal(HttpServletRequest request){
        return userLoginService.selectPersonal(request);
    }
}
